package com.sptpc.demo.service.impl;

import com.sptpc.demo.mapper.CategoryMapper;
import com.sptpc.demo.model.Category;
import com.sptpc.demo.service.ICategoryService;
import com.sptpc.demo.vo.CategoryWithDrinksVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService implements ICategoryService {
    @Autowired
    public CategoryMapper categoryMapper;

    @Override
    public List<Category> getAllCategories() {
        return categoryMapper.selectAll();
    }

    @Override
    public void addNewCategory(Category category) {
            categoryMapper.insert(category);
    }

    @Override
    public Category getCategoryById(Long id) {
        return categoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateCategory(Category category) {
            categoryMapper.updateByPrimaryKeySelective(category);
    }

    @Override
    public void deleteCategoryById(Long id) {
        categoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<CategoryWithDrinksVo> getCategoryWithDrinks(Long id) {
        return categoryMapper.selectWithDrinksById(id);
    }
}
